<?php

class Model_Product extends Model {
    
    private $table = 'products';
    
    public function getProduct($id)
    {
        $sql = "SELECT p.* FROM {$this->table} AS p WHERE p.id = ?";
        return $this->db->query($sql, $id)->fetch();
    }
    
    public function getProductList()
    {
        $sql = "SELECT p.*, c.name AS category_name FROM {$this->table} AS p LEFT JOIN categories AS c ON c.id=p.category_id";
        return $this->db->query($sql)->fetchAll();
    }
    
    public function getProductById($id)
    {
        $sql = "SELECT p.* FROM {$this->table} AS p WHERE p.id=?";
        return $this->db->query($sql, array($id))->fetch();
    }
}